﻿// <copyright file="Window1.xaml.cs" company="Oleg V. Polikarpotchkin">
// Copyright © 2008-2009 Oleg V. Polikarpotchkin. All Right Reserved
// </copyright>
// <author>Oleg V. Polikarpotchkin</author>
// <email>ov-p@yandex.ru</email>
// <date>2009-01-23</date>
// <summary>OpenWPFChart library. SerialAxis Test app.</summary>
// <revision>$Id$</revision>

using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using OpenWPFChart.Helpers;
using OpenWPFChart.Parts;

namespace SeriesAxisTest
{
	/// <summary>
	/// SerialAxis Test app main Window.
	/// </summary>
	public partial class Window1 : Window
	{
		public Window1()
		{
			InitializeComponent();
		}

		/// <summary>
		/// Executes <see cref="NavigationCommands.Zoom"/> command.
		/// </summary>
		/// <param name="sender">The sender.</param>
		/// <param name="e">The <see cref="System.Windows.Input.ExecutedRoutedEventArgs"/> instance containing the event data.</param>
		private void ZoomExecutedCommandHandler(object sender, ExecutedRoutedEventArgs e)
		{
			double zoom = 1.2;
			if (e.Parameter != null)
			{
				try
				{
					zoom = Convert.ToDouble(e.Parameter);
				}
				catch (Exception ex)
				{
					Trace.WriteLine("ZoomCommandHandler " + ex.Message);
					return;
				}
			}

			if (zoom == 0.0)
				return;
			if (zoom < 0.0)
				zoom = -1.0 / zoom;

			axis.AxisScale.Scale *= zoom;
		}

		/// <summary>
		/// Handles the Click event of the AxisProperties menu items.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
		private void AxisProperties_Click(object sender, RoutedEventArgs e)
		{
			AxisPropertiesDialog dlg = new AxisPropertiesDialog(axis) { Owner = this };
			if (dlg.ShowDialog() == true)
			{
				SeriesAxisDataView axisData = dlg.AxisData as SeriesAxisDataView;

				axis.BeginInit();
				axis.AxisScale.Start = dlg.Start;
				axis.AxisScale.Stop = dlg.Stop;
				axis.AxisScale.Scale = dlg.Scale;
				axis.ContentLayout = axisData.ContentLayout;
				ChartSeriesScale seriesScale = axis.AxisScale as ChartSeriesScale;
				seriesScale.LongTickAnchor = axisData.LongTickAnchor;
				seriesScale.LongTickRate = axisData.LongTickRate;
				//axis.TickLength = axisData.TickLength;
				//axis.LongTickLength = axisData.LongTickLength;
				Axis.SetTickLength(panel, axisData.TickLength);
				Axis.SetLongTickLength(panel, axisData.LongTickLength);
				axis.LabelFormat = axisData.LabelFormat;
				Axis.SetLabelMargin(panel, axisData.LabelMargin);
				Axis.SetPen(panel, new Pen()
				{
					Brush = new SolidColorBrush(axisData.PenColor),
					Thickness = axisData.PenThickness
				});
				Axis.SetFontFamily(panel, axisData.FontFamily);
				Axis.SetFontSize(panel, axisData.FontSize);
				Axis.SetFontStretch(panel, axisData.FontStretch);
				Axis.SetFontStyle(panel, axisData.FontStyle);
				Axis.SetFontWeight(panel, axisData.FontWeight);
				axis.EndInit();
			}
		}

		/// <summary>
		/// Handles the Click event of the Exit control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
		private void Exit_Click(object sender, RoutedEventArgs e)
		{
			Close();
		}
	}
}
